package edu.calvin.djs32.cs214.interpreters.calculator.primitives;

import ovm.polyd.PolyD;
import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;
import edu.calvin.djs32.cs214.interpreters.calculator.Primitive;

public class GreaterThanPrimitive implements Primitive, IGreaterThanPrimitive{

	public HobbesTIR apply(HobbesTIR... tir) {
		IGreaterThanPrimitive dispatcher = PolyD.build(IGreaterThanPrimitive.class, this);
		return dispatcher.greaterThan(tir[0], tir[1]);
	}
	
	public HobbesTIR greaterThan(IntegerTIR tir1, IntegerTIR tir2) {
		if (tir1.getInt() > tir2.getInt()){
			return new StringTIR("true");
		}else{
			return new TupleTIR();
		}
	}
	
	public HobbesTIR greaterThan(StringTIR tir1, StringTIR tir2) {
		if (tir1.getString().compareTo(tir2.getString()) > 0){
			return new StringTIR("true");
		}else{
			return new TupleTIR();
		}
	}
	
	public HobbesTIR greaterThan(HobbesTIR tir1, HobbesTIR tir2) {
		throw new IllegalStateException("unimplemented!");
	}
}
